using System;
using System.Collections.Generic;
using System.Text;
using PH.Common;

namespace Hoshimi
{
    public class ShooterBot_AttackTargetState : State
	{
		#region Singleton

		// Fields
		protected static ShooterBot_AttackTargetState instance;

		// Constructor
		protected ShooterBot_AttackTargetState() : base() { }

		// Methods
		public static ShooterBot_AttackTargetState Instance()
		{
			// Uses "Lazy initialization"
			if( instance == null ) 
				instance = new ShooterBot_AttackTargetState();

			return instance;
		}

		#endregion

		public override bool Play( Unit unit ) 
        {
			ShooterBot bot = (ShooterBot) unit;

            bot.SetName("Attack");

            // We cant give order to the bot. We stop
			if (	bot.State != NanoBotState.WaitingOrders	&& 
					bot.State != NanoBotState.Moving			&&
					bot.State != NanoBotState.Defending)
			{
				return true;
			}

            if (!bot.HasEnnemyTarget())
            {
                unit.myStateMachine.ChangeState(ShooterBot_RestState.Instance());
                return false;
            }

            bot.AttackEnnemy();

            unit.myStateMachine.ChangeState(ShooterBot_RestState.Instance());
			return true;
		}
	}
}
